#coding:utf-8
import sys
sys.path.append("..")

import time


class TXTClient(object):

    #写入文件
    def write(self, file_path, mode, content):
        try:
            block_sz = 8192
            #mode：{'w':'覆盖','a':'追加','wb':'字节流'}
            with open(file_path, mode, encoding="utf-8") as file: #binary mode doesn't take an encoding argument
                if mode == 'wb' :
                    while True:
                        buffer = content.read(block_sz)
                        if not buffer:
                            break
                        file.write(buffer)
                else :
                    file.write(content)
        except Exception as e:
            print(e)
        return file_path


    #生成行数据列表
    def read(self, file_path):
        try:
            with open(file_path, 'r', encoding='utf-8') as file:
                lines = file.readlines()
        except Exception as e:
            print(e)

        return lines



if __name__ == "__main__":
    #记录执行开始时间
    str_time = int(time.time())

    #实例化类
    obj = TXTClient()

    # 读取原文件
    lines = obj.readlines('D:\\usr\\EJU\\数据部门\\大数据系统\\商业客户数据部\\数据迁移\\待入库文件20210111\\写字楼-房天下.txt')
    #跳过第一行表头
    header = lines.pop(0)
    print(header)

    maxRow = len(lines)
    print("总记录数", maxRow)

    insertDataList = []
    for line in lines:
        print(line)

    end_time = int(time.time())
    print("程序执行时间（秒）：", end_time - str_time)



